﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NibbleOil.Web.Business.Model;

namespace NibbleOil.Web.Historial
{
    public partial class OrdenServicio : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnConsultar_Click(object sender, EventArgs e)
        {
            IQueryable<ORDENSERVICIO> ordenes = Business.DataContext.Instance.Model.ORDENSERVICIO.Where(x => x.Patente == txtPatenteNro.Text.ToUpper());

            if (ordenes.Count<ORDENSERVICIO>() == 0)
            {
                lblMensaje.Text = "El numero de patente ingresado es incorrecto.";
            }
            else
            {
                lblMensaje.Text = string.Empty;
                InsertHtmlContent(ordenes.FirstOrDefault<ORDENSERVICIO>().PaginaHTML);
            }
        }

        private void InsertHtmlContent(string html)
        {
            PopUpModal.InnerHtml = html + "<a class='close-reveal-modal'>&#215;</a>";
            ScriptManager.RegisterClientScriptBlock(btnConsultar, this.GetType(), "AlertMsg", "<script language='javascript'>$('#callPopModal').click();</script>", false);
        }
    }
}